<template>
  <div class="home-container">
    <el-container>
        <el-header>
		<div>
            <img src="../assets/xatu.png"/>
            <span>学生管理系统</span>
		</div>
        <el-dropdown>
        <span class="el-dropdown-link"><img src="../assets/header.png"/>你好,管理员{{user.adminid}}
        <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-plus" @click.native="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
        </el-dropdown>
        </el-header>
        <el-container>
        <el-aside>
			<!-- 导航菜单 -->
			<el-menu
                class="el-menu-vertical-demo"
                background-color="#333744"
                text-color="#fff"
                active-text-color="#ffd04b">
            <el-menu-item index="2" @click="goADstudentcenter">
                <i class="el-icon-menu"></i>
                <span slot="title">学生管理</span>
            </el-menu-item>
            <el-menu-item index="3" @click="goADteachercenter">
                <i class="el-icon-menu"></i>
                <span slot="title">教师管理</span>
            </el-menu-item>
            <el-menu-item index="4" @click="goADclasscenter">
                <i class="el-icon-menu"></i>
                <span slot="title">班级管理</span>
            </el-menu-item>
            <el-menu-item index="5" @click="goADcoursecenter">
                <i class="el-icon-menu"></i>
                <span slot="title">课程管理</span>
            </el-menu-item>
            </el-menu>
		</el-aside>
        <el-main>
			<router-view></router-view>
		</el-main>
        </el-container>
    </el-container>
</div>
</template>

<script>
    import axios from 'axios';
    import {mapState} from 'vuex';
    export default {
        name:'AdminHome',
        computed:{
            ...mapState('adminOptions',['user']),
        },
        methods:{
            goADteachercenter(){
                console.log('点击了教师管理中心')
                // 发请求
                axios.post('http://localhost:5000/SchoolManageSys_war_exploded/user/showAllTeachers.do').then(
                    response => {
                        console.log('请求教师列表成功',response.data)
                        this.$store.commit('adminOptions/SHOWTEACHER',response.data)
                        this.$router.push({
                            name:'adteacher',
                        })
                    },
                    error => {
                        console.log('请求教师列表失败',error.message)
                    }
                )
                
            },
            goADstudentcenter(){
                console.log('点击了学生管理中心')
                // 发请求
                axios.post('http://localhost:5000/SchoolManageSys_war_exploded/user/showAllStudents.do').then(
                    response => {
                        console.log('请求学生列表成功',response.data)
                        this.$store.commit('adminOptions/SHOWSTUDENT',response.data)
                        this.$router.push({
                            name:'adstudent',
                        })
                    },
                    error => {
                        console.log('请求学生列表失败',error.message)
                    }
                )
                
            },
            goADclasscenter(){
                console.log('点击了班级管理中心')
                // 发请求
                axios.post('http://localhost:5000/SchoolManageSys_war_exploded/user/showAllClasses.do').then(
                    response => {
                        console.log('请求班级列表成功',response.data)
                        this.$store.commit('adminOptions/SHOWCLASS',response.data)
                        this.$router.push({
                            name:'adclass',
                        })
                    },
                    error => {
                        console.log('请求班级列表失败',error.message)
                    }
                )
                
            },
            goADcoursecenter(){
                console.log('点击了课程管理中心')
                // 发请求
                axios.post('http://localhost:5000/SchoolManageSys_war_exploded/user/showAllCourses.do').then(
                    response => {
                        console.log('请求课程列表成功',response.data)
                        this.$store.commit('adminOptions/SHOWCOURSE',response.data)
                        this.$router.push({
                            name:'adcourse',
                        })
                    },
                    error => {
                        console.log('请求课程列表失败',error.message)
                    }
                )
                
            },
            logout(){
                console.log('我点击了登出按钮')
                
                this.$alert('您确定要退出登录吗', '登出', {
                    confirmButtonText: '确定',
                    callback:() =>{
                        window.sessionStorage.removeItem('token')
                        this.$router.go(0)
                    }
                });
            }
        }
    }   
</script>

<style>

</style>